from openai import OpenAI
from helpers import utils

class Agent:
    def __init__(self, system_content='You are a helpful assistant.'):
        self.__client = OpenAI(api_key=utils.get_env('API_KEY'), base_url=utils.get_env('BASE_URL'))
        self.__model = utils.get_env('MODEL')
        self.__system = self.__get_message('system', system_content)
    
    def ask(self, user_content):
        completion = self.__client.chat.completions.create(
            model=self.__model,
            messages=[self.__system, self.__get_message('user', user_content)]
        )
        return completion.model_dump().get("choices", [{}])[0].get("message", {}).get("content", "").strip()
    
    @staticmethod
    def __get_message(role, content):
        return {'role': role, 'content': content}
